home *** CD-ROM | disk | FTP | other *** search
- /*
- File: SelectoramaUIWin.c
-
- Copyright (c) 1991-6, Adobe Systems Incorporated.
- All rights reserved.
-
- C source file for Windows specific code for Selection example.
- */
-
- #include "Selectorama.h"
-
- /*****************************************************************************/
-
- BOOL WINAPI SelectionProc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam); // Win32 Change
- Boolean Validate (GPtr globals, const HWND hDlg, int *item);
-
- /*****************************************************************************/
-
- void DoAbout (GPtr globals)
- {
- ShowAbout((AboutRecordPtr)gStuff, hDllInstance, AboutID);
- }
-
- /****************************************************************************/
- /* Example for ShowAlert() function which takes a string ID as parameter */
- /* and displays a message box */
- /****************************************************************************/
-
- short ShowAlert (short stringID)
- {
- char szMessage[256];
- char szTitle[128];
-
- LoadString(hDllInstance, stringID, szMessage, sizeof szMessage);
- LoadString(hDllInstance, 2, szTitle, sizeof szTitle);
- return ( MessageBox(NULL, szMessage, szTitle, MB_OK | MB_ICONHAND) );
- }
-
- /*****************************************************************************/
- // Because we want to wait until the user changes the focus
- // from an EditText field to something else, and because we
- // want to ignore validation if the user Cancels, this routine
- // does round of validating fields if it's been flagged.
-
- Boolean Validate (GPtr globals, const HWND hDlg, int *item)
- {
- int32 x = 0;
- Boolean retn = true;
- short numberErr = noErr;
-
- switch (*item)
- {
- case kPercentEdit: // user moving to something not the edit text
- numberErr = FetchNumber(hDlg,
- kPercentEdit,
- kPercentMin,
- kPercentMax,
- &x);
-
- if (numberErr != noErr)
- { // shows alert if there's an error
- AlertNumber(hDlg,
- kPercentEdit,
- kPercentMin,
- kPercentMax,
- &x,
- hDllInstance,
- AlertID,
- numberErr);
- retn = false; // had to pop an error, stay here
- }
-
- // gPercent = (short)x;
-
- break;
- }
- *item = 0;
- return retn;
- }
-
- /*****************************************************************************/
-
- BOOL WINAPI SelectionProc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam) // Win32 Change
- {
- int item = 0;
- int cmd = 0;
- int32 x = 0;
- short numberErr = noErr;
- static GPtr globals=NULL; /* need to be static */
- static int lastItem = 0;
- // static short lastPercent = gPercent;
-
- switch (wMsg)
- {
-
- case WM_INITDIALOG:
-
- /* set up globals */
- globals = (GPtr) lParam;
-
- CenterDialog(hDlg);
-
- SetRadioGroupState(hDlg,
- kUseRadio1,
- kUseRadioLast,
- kUseRadio1 + gWhatChannels);
- SetRadioGroupState(hDlg,
- kFirstItem,
- kLastItem,
- kFirstItem + gWhatArea);
- SetRadioGroupState(hDlg,
- kCreateRadio1,
- kCreateRadioLast,
- kCreateRadio1 + gCreate);
- ShowHideItem(hDlg, kPercentStatic, (gWhatArea == iSelectRandom));
- ShowHideItem(hDlg, kPercentEdit, (gWhatArea == iSelectRandom));
- ShowHideItem(hDlg, kPercentSymbol, (gWhatArea == iSelectRandom));
- StuffNumber(hDlg, kPercentEdit, gPercent);
- if (gWhatArea == iSelectRandom) SelectTextItem(hDlg, kPercentEdit);
-
- /* fall into WM_PAINT */
- case WM_PAINT:
- return FALSE;
- break;
-
- case WM_COMMAND:
- item = COMMANDID (wParam);
- cmd = HIWORD (wParam);
-
- switch (item)
- {
- case ok:
- if (cmd == BN_CLICKED)
- {
- gWhatChannels = GetRadioGroupState(hDlg, kUseRadio1, kUseRadioLast)
- - kUseRadio1;
- gWhatArea = GetRadioGroupState(hDlg, kFirstItem, kLastItem)
- - kFirstItem;
- gCreate = GetRadioGroupState(hDlg, kCreateRadio1, kCreateRadioLast)
- - kCreateRadio1;
- if (gWhatArea == iSelectRandom)
- {
- lastItem = kPercentEdit; // force validate
- if (Validate(globals, hDlg, &lastItem))
- {
- FetchNumber(hDlg, kPercentEdit, kPercentMin, kPercentMax, &x);
- gPercent = (short)x;
- EndDialog(hDlg, item);
- return TRUE;
- }
- }
- else // no iSelectRandom
- {
- EndDialog(hDlg, item);
- return TRUE;
- }
- }
- else Validate(globals, hDlg, &lastItem);
- break;
- case cancel:
- if (cmd == BN_CLICKED)
- {
- gResult = userCanceledErr;
- EndDialog(hDlg, item);
- }
- break;
- case kPercentEdit:
- if (Validate(globals, hDlg, &lastItem))
- {
- if (cmd == EN_KILLFOCUS)
- lastItem = kPercentEdit; // validate will get this
- else if (cmd == EN_CHANGE)
- {
- numberErr = FetchNumber(hDlg,
- kPercentEdit,
- kPercentMin,
- kPercentMax,
- &x);
- if (numberErr == noErr && x != gPercent)
- { // different number, update
- // gPercent = (short)x;
- }
- }
- }
- break;
- default:
- if (item >= kUseRadio1 && item <= kUseRadioLast)
- {
- if (Validate(globals, hDlg, &lastItem))
- {
- if (cmd == BN_CLICKED)
- {
- SetRadioGroupState(hDlg, kUseRadio1, kUseRadioLast, item);
- }
- }
- }
- else if (item >= kCreateRadio1 && item <= kCreateRadioLast)
- {
- if (Validate(globals, hDlg, &lastItem))
- {
- if (cmd == BN_CLICKED)
- SetRadioGroupState(hDlg, kCreateRadio1, kCreateRadioLast, item);
- }
- }
- else if (item >= kFirstItem && item <= kLastItem)
- {
- if (Validate(globals, hDlg, &lastItem))
- {
- if (cmd == BN_CLICKED)
- {
- SetRadioGroupState(hDlg, kFirstItem, kLastItem, item);
- ShowHideItem(hDlg, kPercentStatic, (item == (iSelectRandom + kFirstItem)));
- ShowHideItem(hDlg, kPercentEdit, (item == (iSelectRandom + kFirstItem)));
- ShowHideItem(hDlg, kPercentSymbol, (item == (iSelectRandom + kFirstItem)));
- if (item == (iSelectRandom + kFirstItem)) SelectTextItem(hDlg, kPercentEdit);
- }
- }
- }
- return FALSE;
- break;
- } /* switch (item) */
- break;
- default:
- return FALSE;
- break;
- } /* switch (wMsg) */
- return TRUE;
- }
-
- /*****************************************************************************/
- Boolean DoParameters (GPtr globals)
- {
-
- int nResult = noErr;
- PlatformData *platform;
-
- platform = ((SelectionRecordPtr) gStuff)->platformData;
-
- /* Query the user for parameters. */
-
- nResult = DialogBoxParam(hDllInstance,
- (LPSTR)"SELECTIONPARAM",
- (HWND)platform->hwnd,
- (FARPROC)SelectionProc,
- (LPARAM)globals);
-
- return (nResult == ok); // could be -1
- }
-
- /*****************************************************************************/
-
- /* Initialization and termination code for window's dlls. */
-
- // Win32 Change
- #ifdef WIN32
-
- // Every 32-Bit DLL has an entry point DLLInit
-
- BOOL APIENTRY DLLInit(HANDLE hInstance, DWORD fdwReason, LPVOID lpReserved)
- {
-
- if (fdwReason == DLL_PROCESS_ATTACH)
- hDllInstance = hInstance;
-
- return TRUE; // Indicate that the DLL was initialized successfully.
- }
-
- #else
- /* ------------------------------------------------
- * Code from Borland's window's dll example code.
- * ------------------------------------------------
- */
- #if defined(__BORLANDC__)
- // Turn off warning: Parameter '' is never used; effects next function only
- #pragma argsused
- #endif
-
- // Every DLL has an entry point LibMain and an exit point WEP.
- int FAR PASCAL LibMain( HANDLE hInstance, WORD wDataSegment,
- WORD wHeapSize, LPSTR lpszCmdLine )
- {
- // Required when using Zortech; causes blink to include startup code
- extern __acrtused_dll;
-
- // The startup code for the DLL initializes the local heap (if there is one)
- // with a call to LocalInit which locks the data segment.
- if ( wHeapSize != 0 )
- UnlockData( 0 );
-
- hDllInstance = hInstance;
- return 1; // Indicate that the DLL was initialized successfully.
- }
-
- int FAR PASCAL WEP(int nParam)
- {
- switch (nParam)
- {
- case WEP_SYSTEM_EXIT: // System shutdown in progress
- case WEP_FREE_DLL : // DLL use count is 0
- default : // Undefined; ignore
- return 1;
- }
- }
- #endif
-